package com.appistry.maven.plugin.far.remote.ssh;

import com.jcraft.jsch.JSchException;

/**
 * <code>Ssh</code> class executes a unix command.
 * 
 * <p>
 * The actual action/command is performed/executed by the
 * {@link com.appistry.maven.plugin.far.remote.ssh.SshExec SshExec} handler.
 * This approach keeps all the ssh execution-specific stuff in the handler
 * class.
 * 
 * <p>
 * When used with the {@link com.appistry.maven.plugin.far.remote.ssh.Command
 * Command} pattern, this class serves as the receiver/target object.
 * 
 */
public class Ssh implements RemoteOperation {

	private String command;
	private SshConfig sshConfig;
	private SshExec delegate;

	public Ssh() {
		super();
	}

	public String getCommand() {
		return command;
	}

	public void setCommand(String command) {
		this.command = command;
	}

	public SshConfig getSshConfig() {
		return sshConfig;
	}

	public void setSshConfig(SshConfig sshConfig) {
		this.sshConfig = sshConfig;
	}

	public SshExec getDelegate() {
		return delegate;
	}

	/**
	 * Executes the command
	 * 
	 * @throws JSchException
	 */
	public void run() throws JSchException {
		// would it be a better idea to construct this in the constructor of
		// this class or perhaps injected via a setter?
		delegate = new SshExec(sshConfig);

		delegate.executeCommand(command);
	}

}
